home *** CD-ROM | disk | FTP | other *** search
- ////////////////////////////////////////////////////////////////
- // rational.h: Rational number class definition.
- // Copyright(c) 1992 Azarona Software. All rights reserved.
- ////////////////////////////////////////////////////////////////
- #ifndef H_RATIONAL
- #define H_RATIONAL
- #include <iostream.h>
-
- class Rational {
- private:
- long n, d; // Numerator and denominator
- public:
- // Constructors and assignment
- Rational();
- Rational(long u);
- Rational(long u, long v);
- Rational(const Rational &r);
- Rational &operator=(const Rational &r);
- // Helper functions
- long Numerator() const;
- long Denominator() const;
- void Set(long u, long v);
- void Simplify();
- void Invert();
- void Negate();
- long RemoveWholePart();
- int IsUndefined() const;
- int IsPositive() const;
- int IsNegative() const;
- int IsZero() const;
- // Stream I/O operators
- friend istream &operator>>(istream &s, Rational &r);
- friend ostream &operator<<(ostream &s, const Rational &r);
- // Arithmetic operators that modify their operand
- Rational operator++(int); // Postfix
- Rational operator--(int); // Postfix
- Rational &operator++(); // Prefix
- Rational &operator--(); // Prefix
- Rational &operator+=(const Rational &r);
- Rational &operator-=(const Rational &r);
- Rational &operator*=(const Rational &r);
- Rational &operator/=(const Rational &r);
- // Arithmetic operators resulting in new object
- Rational operator-() const;
- Rational operator+() const;
- friend Rational operator*(const Rational &a, const Rational &b);
- friend Rational operator/(const Rational &a, const Rational &b);
- friend Rational operator+(const Rational &a, const Rational &b);
- friend Rational operator-(const Rational &a, const Rational &b);
- // Comparison operators
- friend int operator==(const Rational &a, const Rational &b);
- friend int operator!=(const Rational &a, const Rational &b);
- friend int operator<(const Rational &a, const Rational &b);
- friend int operator<=(const Rational &a, const Rational &b);
- friend int operator>(const Rational &a, const Rational &b);
- friend int operator>=(const Rational &a, const Rational &b);
- };
-
- #endif
-